package yjj.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import yjj.system.entity.RolePermission;
import yjj.system.mapper.RolePermissionMapper;
import yjj.system.service.RolePermissionService;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {
    @Override
    public List<String> getPermissionByRoleId(String roleId) {
        LambdaQueryWrapper<RolePermission> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RolePermission::getRoleId, roleId);
        List<RolePermission> list = this.list(queryWrapper);
        if (!list.isEmpty()) {
            return list.stream().map(RolePermission::getPermissionId).collect(Collectors.toList());
        }
        return null;
    }
}
